package com.watermeter.android.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.watermeter.android.R;
import com.watermeter.android.activity.ChangeInfoActivity;
import com.watermeter.android.activity.DownloadRouteActivity;
import com.watermeter.android.activity.LurucbActivity;
import com.watermeter.android.entry.DnowDate;
import com.watermeter.android.entry.DownRoute;
import com.watermeter.android.entry.Rows;
import com.watermeter.android.entry.UpRoute;
import com.watermeter.android.utils.UConstants;
import com.watermeter.android.utils.Util;

import java.util.List;

/**
 * 已抄表
 * Created by zouqh on 2016/5/23.
 */
public class YesCBAdapter extends BaseAdapter {
    private Context context;
    private List<UpRoute> rowses;

    public YesCBAdapter(Context context, List<UpRoute> rowses) {
        this.context = context;
        this.rowses = rowses;
    }

    @Override
    public int getCount() {
        return rowses.size();
    }

    @Override
    public Object getItem(int position) {
        return rowses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHodler viewHodler;
        if (convertView == null) {
            viewHodler = new ViewHodler();
            convertView = LayoutInflater.from(context).inflate(R.layout.yes_cb_item, null);
            viewHodler.code = (TextView) convertView.findViewById(R.id.code);
            viewHodler.byds = (TextView) convertView.findViewById(R.id.byds);
            viewHodler.changeBtn = (Button) convertView.findViewById(R.id.changeBtn);
            viewHodler.tbsl = (TextView) convertView.findViewById(R.id.tbsl);
            viewHodler.cbrq = (TextView) convertView.findViewById(R.id.cbrq);
            viewHodler.syds = (TextView) convertView.findViewById(R.id.syds);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHodler) convertView.getTag();
        }
        int a=rowses.get(position).getSBZD();
        int b=Integer.parseInt(rowses.get(position).getSBQD());
        viewHodler.code.setText("客户编号：" + rowses.get(position).getUSERID());
        viewHodler.byds.setText("当月读数：" + a);
        viewHodler.syds.setText("上月读数：" +b);
        viewHodler.cbrq.setText("抄表日期：" +rowses.get(position).getCBRQ());
        viewHodler.tbsl.setText("退补水量：" +rowses.get(position).getTBSL());
        if(Util.NoNull(UConstants.ShowTBSL)&&UConstants.ShowTBSL.equals("1")){
            viewHodler.tbsl.setVisibility(View.VISIBLE);
        }else{
            viewHodler.tbsl.setVisibility(View.GONE);
        }


        viewHodler.changeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent=new Intent(context, ChangeInfoActivity.class);
//                intent.putExtra("id",position+"");
//                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHodler {
        TextView code;
        TextView byds;
        TextView tbsl;
        TextView syds;
        Button changeBtn;
        TextView cbrq;

    }
}
